import {queryFileDirByGroup,getPreviewLinkPath, queryScanTree,queryGroupAdmin,addGroupApply,quickDownloadGroupFiles} from '@/services/workspace';
export default {
  namespace: 'groupModel',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },
    queryForm: {},
    groupAdmin:[],
  },

  effects: {
    * queryFileDirByGroup({payload}, {call, put}) {
      const response = yield call(queryFileDirByGroup, payload);
      if(response&&response.result=='ok'){

      yield put({
        type: 'save',
        payload: response,
      });
      }
    },
    * queryScanTree({payload, callback,}, {call, put}) {
      const response = yield call(queryScanTree, payload);

      if (response.result == 'ok') {
        yield put({
          type: 'saveScanData',
          payload: response,
        });
      }

    },
    //申请下载
    * addDownloadApply({payload, callback}, {call, put}) {
      const response = yield call(addGroupApply, payload);
      if (callback) callback(response);
    },

    * getPreviewLinkPath({payload, callback}, {call, put}) {
      const response = yield call(getPreviewLinkPath, payload);
      if (callback) callback(response);
    },
    * queryGroupAdmin({payload, callback,}, {call, put}) {
      const response = yield call(queryGroupAdmin, payload);
      if(response&&response.result=='ok'){
        yield put({
          type: 'saveGroupAdmin',
          payload: response,
        });
      }

      if (callback) callback(response);
    },
    //下载公共文件
    * quickDownloadGroupFiles({payload, callback}, {call, put}) {
      const response = yield call(quickDownloadGroupFiles, payload);
      if (callback) callback(response);
    },
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
    /**
     * 文件扫描结果
     * @param state
     * @param action
     * @returns {{usersData: *}}
     */
    saveScanData(state, action) {
      return {
        ...state,
        scanData: action.payload.data,
      };
    },
    saveGroupAdmin(state, action) {
      return {
        ...state,
        groupAdmin: action.payload.data,
      };
    },
  },
};
